#!/bin/bash
BaseDir=$(cd "$(dirname "$0")"; pwd)
cd ${BaseDir}

set -x
set -o errexit

cp -f kubesphere3_aio_cfg.yaml ../kubesphere-all-v3.0.0-offline-linux-amd64/.
cp -f private_key ../kubesphere-all-v3.0.0-offline-linux-amd64/.

pushd ../kubesphere-all-v3.0.0-offline-linux-amd64

sudo ./kk init os -f kubesphere3_aio_cfg.yaml -s ./dependencies/ --add-images-repo

grep -rins 'dockerhub.kubekey.local' /etc/hosts || (
  echo "192.168.99.1 dockerhub.kubekey.local" >> /etc/hosts
)
curl -k https://dockerhub.kubekey.local/v2/
ping -c 1 dockerhub.kubekey.local

# 部署
sudo ./kk create cluster -f kubesphere3_aio_cfg.yaml

# 访问地址
echo "Console: http://192.168.99.10:30880
Account: admin
Password: P@88w0rd
"
popd

vagrant ssh kubesphere-dev -c "/home/vagrant/cmd-completion.sh"